#ifndef _THREADPOOL_H_
#define _THREADPOOL_H_

#include <pthread.h>

// it is one task
typedef struct pool_task_t{
    int connfd;
    int priority;
} pool_task_t;

// it is the work queue queue
typedef struct task_queue_t {
    pool_task_t *queue; // array of pool_task_t (a task)
    int length;
    int heap_size;
} task_queue_t;

// it is the thread pool
typedef struct pool_t {
  pthread_mutex_t lock;
  pthread_cond_t get_task;
  pthread_cond_t fill_task;
  pthread_t *threads;
  task_queue_t work_queue;
  int thread_count;
} pool_t;

#define MAX_THREADS   20
#define TASK_QUEUE_SIZE  20

pool_t *pool_create(int thread_count, int queue_size);
int pool_add_task(pool_t *pool, int connfd);
int pool_destroy(pool_t *pool);

#endif
